home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Informant Complete 1995 - 2000
/
Delphi Informant Complete 1995 to 2000.iso
/
Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar
/
1998
/
Sep
/
di9809am
/
Compont
/
Versions
/
Ver_1.1
/
TAPIcomp.pas
< prev
Wrap
Pascal/Delphi Source File
|
1998-06-26
|
39KB
|
1,007 lines
{+--------------------------------------------------------------------------+
| Component: TkkamTAPI
| Created: 6/3/98 6:35:50 PM
| Author: Alan Moore and Ken Kyler
| developed for article in Delphi Informant; September 1998
| Copyright 1998, all rights reserved.
| Description: TAPI non-visual component for basic Telephony functionality
| Version: 1.1
| Modification History: Modifications by Ken Kyler and Alan Moore
+--------------------------------------------------------------------------+}
unit TAPIcomp; { TkkamTAPI component. }
{ Created 6/3/98 6:35:51 PM }
{ Eagle Software CDK, Version 3.02 Rev. F }
interface
uses
Windows, SysUtils, Messages, Classes, Graphics, Controls, Forms,
Dialogs, Tapi, Menus, StdCtrls, ExtCtrls;
type
// Thread Action Type
TThreadAction = (taSuspend, taResume, taTerminate);
// Comm Event Type
TCommEvent = (tceDSR, tceDTR, tceCTS, tcePORT);
// Event Types
TTapiUpdateEvent = procedure(sender : TObject; UpdateList : TStringList)
of object;
TCommThreadEvent = procedure(sender : TObject; ThreadAction : TThreadAction)
of object;
TCommEventProc = procedure (sender : TObject; ACommEvent : TCommEvent;
AStatus : integer) of object;
// Our Thread Class moved from separate unit
type
TCommStatus = class(TThread)
private
{ Private declarations }
ThePort : THandle;
function GetPort : THandle;
procedure SetPort(Value : THandle);
protected
TheOwner: TComponent;
property APort : THandle
read GetPort
Write SetPort;
procedure Execute; override;
procedure TriggerTapiCommEvent(Sender : TObject;
CommEvent : TCommEvent; Status : integer);
public
constructor Init(Owner : TComponent; Suspended : Boolean;
PortRead : THandle);
end;
// constants for thread and modem lights
const
off = 0;
red = 1;
yellow = 2;
green = 3;
type
// Main TAPI Class
TkkamTAPI = class(TComponent)
private
FAnswerCalls: Boolean;
FPulseDialing: boolean;
FCountryCode: integer;
FVersion: integer;
{ Private declarations }
FLineCallParams: TLineCallParams;
FLineTranslateOptions: DWord;
FExt: TLINEEXTENSIONID;
FlpTranslateOutput: LPLINETRANSLATEOUTPUT;
FPort: THandle;
FTAPI_Initialized: Boolean;
FAutoSelectLine: Boolean;
FDev: Integer;
FPhoneNumber: String;
FMediaMode: DWord;
FBearerMode: DWord;
FLineIsOpen: Boolean;
FAnswserCalls : boolean;
FOnCreateCallManager: TTapiUpdateEvent;
FOnShutdownManager: TTapiUpdateEvent;
FOnDestroyCallManager : TTapiUpdateEvent;
FOnFreeCallManager: TTapiUpdateEvent;
FOnEnumerateDevices: TTapiUpdateEvent;
FOnOpenLine: TTapiUpdateEvent;
FOnDial: TTapiUpdateEvent;
FOnCommThreadEvent: TCommThreadEvent;
FOnTriggerCommEvent: TCommEventProc;
FOnTAPIInit: TNotifyEvent; { Defined in Classes unit. }
// The next three events will usually not need to be used but are included
// in case you want to take additional steps after these changes occur.
// Generally, you should communicate from the calling application to this
// component to effect each of these changes
FOnPhoneNumberChange: TNotifyEvent; { Defined in Classes unit. }
FOnChangeMediaMode: TNotifyEvent; { Defined in Classes unit. }
FOnChangeBearerMode: TNotifyEvent; { Defined in Classes unit. }
function ReadPhoneNumber : string;
procedure WritePhoneNumber(NewPhoneNumber : String);
protected
{ Protected declarations }
InitResults : TStringList;
DeviceList: TStringList;
ShutdownResults: TStringList;
CreateManagerResults : TStringList;
DialResults: TStringList;
{ Event triggers: }
procedure TriggerCreateCallManagerEvent; virtual;
procedure TriggerShutdownManagerEvent; virtual;
procedure TriggerDestroyCallManagerEvent; virtual;
procedure TriggerEnumerateDevicesEvent; virtual;
procedure TriggerTAPIInitEvent; virtual;
procedure TriggerOpenLineEvent; virtual;
procedure TriggerDialEvent; virtual;
procedure TriggerPhoneNumberChangeEvent; virtual;
procedure TriggerChangeMediaModeEvent; virtual;
procedure TriggerChangeBearerModeEvent; virtual;
procedure TriggerCommThreadEvent(ThreadAction : TThreadAction); virtual;
procedure TriggerCommEvent(Sender : TObject;
ACommEvent : TCommEvent; AStatus : integer);
public
{ Public declarations }
CommStatusThread : TCommStatus;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function TapiInitialize: Boolean;
procedure EnumerateDevices;
function ShutdownManager: Boolean;
function CreateCallManager: Boolean;
function CheckLineIsOpen: boolean;
procedure ChangePhoneNumber(NewPhoneNumber : string);
function Dial: String;
procedure ChangeMediaMode(MediaModeSelected : Integer);
procedure ChangeBearerMode(BearerModeSelected : Integer);
procedure ShowLineTranslateDialog(APhoneNum : string; AHandle : THandle);
function OpenLine(AcceptCalls : boolean; var OpenMsg : string): boolean;
property APort : THandle read FPort Write FPort;
// Use a MaskEdit on main form to enter phone number with the following
// edit mask: !9 \(999\) 000-0000;1;_
property PhoneNumber: String read ReadPhoneNumber write WritePhoneNumber;
property TAPI_Initialized: Boolean read FTAPI_Initialized write
FTAPI_Initialized;
property MediaMode: DWord read FMediaMode write FMediaMode;
property Dev: Integer read FDev write FDev; { Public }
property LineIsOpen : boolean read FLineIsOpen Write FLineIsOpen;
published
{ Published properties and events }
property AutoSelectLine: Boolean read FAutoSelectLine write FAutoSelectLine
default true;
property AnswerCalls : boolean read FAnswerCalls Write FAnswerCalls;
property PulseDialing : boolean read FPulseDialing Write FPulseDialing;
property OnCreateCallManager: TTapiUpdateEvent read FOnCreateCallManager write
FOnCreateCallManager;
property OnShutdownManager: TTapiUpdateEvent read FOnShutdownManager
write FOnShutdownManager;
property OnDestroyCallManager: TTapiUpdateEvent read FOnDestroyCallManager
write FOnDestroyCallManager;
property OnEnumerateDevices: TTapiUpdateEvent read FOnEnumerateDevices
write FOnEnumerateDevices;
property OnTriggerCommEvent : TCommEventProc read FOnTriggerCommEvent
Write FOnTriggerCommEvent;
property OnTAPIInit: TNotifyEvent read FOnTAPIInit write FOnTAPIInit;
property OnOpenLine: TTapiUpdateEvent read FOnOpenLine write FOnOpenLine;
property OnDial: TTapiUpdateEvent read FOnDial write FOnDial;
property OnPhoneNumberChange: TNotifyEvent read FOnPhoneNumberChange
write FOnPhoneNumberChange;
property OnChangeMediaMode: TNotifyEvent read FOnChangeMediaMode
write FOnChangeMediaMode;
property OnChangeBearerMode: TNotifyEvent read FOnChangeBearerMode
write FOnChangeBearerMode;
property OnCommThreadEvent : TCommThreadEvent read FOnCommThreadEvent
Write FOnCommThreadEvent;
end; { TkkamTAPI }
var
LineApp: HLINEAPP;
procedure Register;
implementation
const
Ver = $00010004; // API version accepted (1.4) [Windows 95]
// Local Variables -------------------------------------------------------------
var
TapiMessages : TStringList; // local string list for TAPI results
Devices : TStringList; // local string list for available devices
AkkamTAPI : TkkamTAPI; // local copy of the TAPI component
LocalNumDevs : Integer; // local copy of number of devices
ALineIsOpen : boolean; // local copy of line open status
ALine : HLine; // local copy of line
ACall : HCall; // local copy of call
APhoneNumber : str